package org.fly.jingwei.config;

import freemarker.template.TemplateModelException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * freemarker 配置类
 *
 * @author leo.jie (weixiao.me@aliyun.com)
 * @version 1.0
 * @organization bigdata
 * @website https://www.jielongping.com
 * @date 2020/5/28 10:18 下午
 * @since 1.0
 */
@Configuration
public class FreeMarkerConfig {
    @Autowired
    protected freemarker.template.Configuration configuration;

    /**
     * 添加自定义标签
     */
    @PostConstruct
    public void setCustomTag() {
        Map<String, Object> configs = new HashMap<>(2);
        configs.put("staticWebSite", "http://localhost:8080");
        configs.put("siteUrl", "http://localhost:8080/");
        try {
            configuration.setSharedVariable("config", configs);
        } catch (TemplateModelException e) {
            e.printStackTrace();
        }
    }
}
